package com.yztc.orangeentertainment.ui.main.subscribefragment.staritem;

import android.content.Context;
import android.util.Log;

import com.yztc.orangeentertainment.bean.staritembean.StarInfoBean;
import com.yztc.orangeentertainment.bean.staritembean.StarInfoStarBean;
import com.yztc.orangeentertainment.config.SubscribeUrlConfig;
import com.yztc.orangeentertainment.http.SubscribeRetrofitService;

import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by My on 2016/10/7.
 */
public class StarItemModle implements StarItemContract.Modle {
    @Override
    public void getStarItemAll(String type, Map<String, String> params, final OnLoadStarItemListener loadStarItemListener, Context context) {
        Retrofit retrofit=new Retrofit.Builder()
                .baseUrl(SubscribeUrlConfig.PATH.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        Call<StarInfoBean> call=retrofit.create(SubscribeRetrofitService.class).getStarItemAll(type,params);
        call.enqueue(new Callback<StarInfoBean>() {
            @Override
            public void onResponse(Call<StarInfoBean> call, Response<StarInfoBean> response) {
                if (response.isSuccessful()) {
                    StarInfoStarBean starBean = response.body().getData().getStar();
                    loadStarItemListener.onSuccess(starBean);
                }else {
                    Log.i("tag","wrong");
                }
            }

            @Override
            public void onFailure(Call<StarInfoBean> call, Throwable t) {

            }
        });
    }
}
